package com.zhuiyun.educations.api.newCourse.controller;

import cn.hutool.core.collection.CollUtil;
import com.zhuiyun.educations.api.course.entity.Course;
import com.zhuiyun.educations.api.newCourse.entity.CourseInfo;
import com.zhuiyun.educations.api.newCourse.entity.CourseUnit;
import com.zhuiyun.educations.api.newCourse.entity.DTO.CourseDTO;
import com.zhuiyun.educations.api.newCourse.entity.UnitJoint;
import com.zhuiyun.educations.api.newCourse.service.ICourseService;
import com.zhuiyun.educations.common.response.CommonResult;
import com.zhuiyun.educations.util.pageUtil.PageRequest;
import com.zhuiyun.educations.util.pageUtil.PageResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName CourseController
 * @Description TODO 课程后端控制层
 * @Author 杨友朋
 * @Date 2023/6/28 16:54
 **/
@RestController
@CrossOrigin
@RequestMapping("/newCourse")
public class ICourseController {
    @Resource
    ICourseService iCourseService;

    /**
    * @Author 杨友朋
    * @Description TODO 统计每个老师的上架课程数量
    * @Date 2023/8/9 15:40
    * @Return
    * @param
    */
    @GetMapping("/teacherEcharts")
    public CommonResult teacherEcharts(){
        List<CourseDTO> list = iCourseService.selectCountByTeacher();
        return CommonResult.ok(list);
    }

    /**
     * @Author 杨友朋
     * @Description TODO 统计每个科目的上架课程数量
     * @Date 2023/8/9 15:40
     * @Return
     * @param
     */
    @GetMapping("/subjectEcharts")
    public CommonResult subjectEcharts(){
        List<CourseDTO> list = iCourseService.selectCountBySubject();
        return CommonResult.ok(list);
    }

    /**
     * @Author 杨友朋
     * @Description TODO 全查课程
     * @Date 2023/6/26 14:09
     * @Return CommonResult
     * @param courseDTO,pageRequest
     */
    @GetMapping("/selectCourse")
    public CommonResult selectCourse(CourseDTO courseDTO, PageRequest pageRequest){
        return CommonResult.ok(iCourseService.selectCourse(courseDTO,pageRequest));
    }

    /**
     * @Author 杨友朋
     * @Description TODO 全查课程
     * @Date 2023/6/26 14:09
     * @Return CommonResult
     * @param courseDTO,pageRequest
     */
    @GetMapping("/selectCoursePc")
    public CommonResult selectCoursePc(CourseDTO courseDTO, PageRequest pageRequest){
        return CommonResult.ok(iCourseService.selectCoursePc(courseDTO,pageRequest));
    }

    /**
    * @Author 杨友朋
    * @Description TODO 根据课程id查询课程下的章节
    * @Date 2023/6/29 9:56
    * @Return CommonResult
    * @param courseDTO,pageRequest
    */
    @GetMapping("/selectUnit")
    public CommonResult selectUnit(CourseDTO courseDTO, PageRequest pageRequest) {
        return CommonResult.ok(iCourseService.selectUnit(courseDTO,pageRequest));
    }

    /**
    * @Author 杨友朋
    * @Description TODO 根据章节id查询章节下的详细课程
    * @Date 2023/6/29 9:57
    * @Return CommonResult
    * @param courseDTO,pageRequest
    */
    @GetMapping("/selectJoint")
    public CommonResult selectJoint(CourseDTO courseDTO, PageRequest pageRequest) {
        return CommonResult.ok(iCourseService.selectJoint(courseDTO,pageRequest));
    }

    /**
    * @Author 杨友朋
    * @Description TODO 添加章节
    * @Date 2023/6/29 9:58
    * @Return CommonResult
    * @param courseUnit
    */
    @PostMapping("/insertUnit")
    public CommonResult insertUnit(@RequestBody CourseUnit courseUnit){
        return iCourseService.insertUnit(courseUnit);
    }

    /**
    * @Author 杨友朋
    * @Description TODO 添加详细课程
    * @Date 2023/6/29 9:59
    * @Return CommonResult
    * @param unitJoint
    */
    @PostMapping("/insertJoint")
    public CommonResult insertJoint(@RequestBody UnitJoint unitJoint){
        return iCourseService.insertJoint(unitJoint);
    }

    /**
    * @Author 杨友朋
    * @Description TODO 添加课程信息
    * @Date 2023/6/29 9:59
    * @Return CommonResult
    * @param imageFile,courseDTO
    */
    @PostMapping("/insertCourse")
    public CommonResult insertCourse(MultipartFile imageFile, CourseDTO courseDTO){
        return iCourseService.insertCourse(imageFile,courseDTO);
    }

    @PostMapping("/upSwith")
    public CommonResult upSwitch(@RequestBody UnitJoint unitJoint){
        return iCourseService.upSwitch(unitJoint);
    }

    @PostMapping("/upJoint")
    public CommonResult upJoint(@RequestBody UnitJoint unitJoint){
        return iCourseService.upJoint(unitJoint);
    }

    /**
     * @Author 杨友朋
     * @Description TODO 根据id修改课程信息
     * @Date 2023/6/26 9:57
     * @Return CommonResult
     * @param imageFile,courseDTO
     */
    @PostMapping("/updateCourseById")
    public CommonResult updateCourseById(MultipartFile imageFile, CourseInfo courseInfo) {
        return iCourseService.updateCourseById(imageFile, courseInfo);
    }

    /**
    * @Author 杨友朋
    * @Description TODO 根据id修改课程状态
    * @Date 2023/6/30 9:51
    * @Return CommonResult
    * @param courseInfo
    */
    @PostMapping("/upStatusById")
    public CommonResult upStatusById(@RequestBody CourseInfo courseInfo){
        return iCourseService.upStatusById(courseInfo);
    }

    /**
    * @Author 杨友朋
    * @Description TODO 根据id删除课程
    * @Date 2023/6/30 9:03
    * @Return CommonResult
    * @param id
    */
    @GetMapping("/delById")
    public CommonResult delById(Integer id){
        return iCourseService.delById(id);
    }

    @GetMapping("/delUnitById")
    public CommonResult delUnitById(Integer id){
        return iCourseService.delUnitById(id);
    }

    @GetMapping("/delOneById")
    public CommonResult delOneById(Integer id){
        return iCourseService.delOneById(id);
    }

    /**
    * @Author 杨友朋
    * @Description TODO 根据ids批量删除课程
    * @Date 2023/6/30 9:07
    * @Return CommonResult
    * @param ids
    */
    @PostMapping("/delByIds")
    public CommonResult delByIds(@RequestBody List<Integer> ids){
        return iCourseService.delByIds(ids);
    }

    /**
     * @Author 杨友朋
     * @Description TODO 根据ids批量删除课程
     * @Date 2023/6/30 9:07
     * @Return CommonResult
     * @param ids
     */
    @PostMapping("/onShelf")
    public CommonResult groundingByIds(@RequestBody List<Integer> ids){
        return iCourseService.onShelf(ids);
    }

    /**
     * @Author 杨友朋
     * @Description TODO 根据ids批量删除课程
     * @Date 2023/6/30 9:07
     * @Return CommonResult
     * @param ids
     */
    @PostMapping("/offShelf")
    public CommonResult upStatus2(@RequestBody List<Integer> ids){
        return iCourseService.offShelf(ids);
    }
}
